package com.grad.webstudy.controller;

import com.grad.webstudy.annota.ApiAuthorization;
import com.grad.webstudy.annota.LoginAuthorization;
import com.grad.webstudy.constants.AuthConstants;
import com.grad.webstudy.model.CourseChapter;
import com.grad.webstudy.service.CourseChapterService;
import com.grad.webstudy.vo.CourseChapterVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description:
 * @Author: zjf
 * @Date: 2020/2/9 10:26.
 */

@RestController
@RequestMapping("/courseChapter")
public class CourseChapterController {

    @Autowired
    private CourseChapterService courseChapterService;


    @PostMapping("/add")
    @ApiAuthorization(auth= AuthConstants.COURSE_ADD)
    public int add(CourseChapter courseChapter) {
        return courseChapterService.addChapter(courseChapter);
    }

    /**
     * 批量添加
     * @param courseChapters
     * @return
     */
    @PostMapping("/addS")
    @ApiAuthorization(auth= AuthConstants.COURSE_ADD)
    public boolean addChapters(List<CourseChapter> courseChapters){
        return courseChapterService.addChapters(courseChapters);
    }


    @DeleteMapping("/delete")
    @ApiAuthorization(auth = AuthConstants.COURSE_DELETE)
    public boolean deleteChapters(String ids){
        return courseChapterService.deleteChapters(ids);
    }


    @DeleteMapping("/deleteByCourseId")
    @ApiAuthorization(auth = AuthConstants.COURSE_DELETE)
    public boolean deleteChaptersByCourseId(Integer courseId){
        return courseChapterService.deleteChaptersByCourseId(courseId);
    }

    @PutMapping("/update")
    @ApiAuthorization(auth=AuthConstants.COURSE_UPDATE)
    public boolean updateChapter(CourseChapter courseChapter){
        return courseChapterService.updateChapter(courseChapter);
    }


    @GetMapping("/queryByCourseId")
    @LoginAuthorization
    public List<CourseChapterVo> queryAllByCourseId(Integer courseId){
        return courseChapterService.queryChaptersByCourseId(courseId);
    }
}
